package com.ruoyi.system.outto.goods.impl;


import com.alibaba.fastjson.JSON;
import com.alibaba.fastjson.JSONObject;
import com.alibaba.fastjson.TypeReference;
import com.ruoyi.common.constant.Constants;
import com.ruoyi.common.core.domain.AjaxResult;
import com.ruoyi.common.exception.GlobalException;
import com.ruoyi.common.utils.StringUtils;
import com.ruoyi.system.V2.gameAttr.mapper.GameAttrTemplateMapper;
import com.ruoyi.system.V2.gameAttr.mapper.GameAttributeMapper;
import com.ruoyi.system.V2.gameAttr.service.IGameAttributeService;
import com.ruoyi.system.V2.goodInfo.mapper.GoodsInfoImgMapper;
import com.ruoyi.system.V2.inter.mapper.ArtRecMapper;
import com.ruoyi.system.interAttr.domain.InterAttr;
import com.ruoyi.system.interAttr.mapper.InterAttrMapper;
import com.ruoyi.system.model.domain.*;
import com.ruoyi.system.model.dto.GoodsInfoAndAttrValueDto;
import com.ruoyi.system.outto.core.LCConstant;
import com.ruoyi.system.outto.dto.yx7881.bean.*;
import com.ruoyi.system.outto.dto.yx7881.core.LieBaoCore;
import com.ruoyi.system.outto.dto.yx7881.utils.HttpUtil;
import com.ruoyi.system.outto.dto.yx7881.utils.LieBaoUtil;
import com.ruoyi.system.outto.goods.INew7881Api;
import lombok.extern.slf4j.Slf4j;
import org.apache.commons.beanutils.ConvertUtils;
import org.apache.commons.collections4.CollectionUtils;
import org.springframework.stereotype.Service;

import javax.annotation.Resource;
import java.lang.reflect.Field;
import java.math.BigDecimal;
import java.util.*;
import java.util.stream.Collectors;


@Slf4j
@Service
public class New7881ApiImpl implements INew7881Api {

    @Resource
    private IGameAttributeService gameAttributeService;
    @Resource
    InterAttrMapper interAttrMapper;
    @Resource
    private GameAttributeMapper gameAttributeMapper;
    @Resource
    private GoodsInfoImgMapper goodsInfoImgMapper;
    @Resource
    private ArtRecMapper artRecMapper;
    @Resource
    private GameAttrTemplateMapper gameAttrTemplateMapper;

    final String DefaultV = "无";

    //参数
    private void Property(YX7881GoodsBean goodsBean, GoodsInfoAndAttrValueDto goodsInfoAndAttrValueDto, SalePartner salePartner) {
        String substring = salePartner.getSaleName();
        InterAttr interAttr = interAttrMapper.selectInterAttrByConfig(substring, goodsInfoAndAttrValueDto.getGameId());
//        goodsBean.setGameId(interAttr.getInterGameId());
        //开始匹配单选属性
        builderRadioAttr(goodsInfoAndAttrValueDto, goodsBean, interAttr.getRadioAttr());
        //开始匹配多选属性
        builderCheckAttr(goodsInfoAndAttrValueDto, goodsBean, interAttr.getCheckAttr());
        //开始匹配输入框属性
        builderInputAttr(goodsInfoAndAttrValueDto, goodsBean, interAttr.getInputAttr());
    }

    /**
     * 开始匹配单选属性
     *
     * @param goodsInfoAndAttrValueDto
     * @param radioAttr
     */
    private void builderRadioAttr(GoodsInfoAndAttrValueDto goodsInfoAndAttrValueDto, YX7881GoodsBean goodsBean, String radioAttr) {
        //========================开始匹配单选属性=====================//
        JSONObject jsonObject = JSONObject.parseObject(radioAttr);
        String interRadioReqs = jsonObject.getString("interRadioReqs");
        log.info(JSONObject.toJSONString(interRadioReqs));
        List<JSONObject> jsonObjects = JSONObject.parseArray(interRadioReqs, JSONObject.class);
        if (org.springframework.util.CollectionUtils.isEmpty(jsonObjects)) {
            throw new GlobalException("接口单选属性暂未配置");
        }
        /**
         * 1、先查询自定义中所有单选的字段
         * 2、再查该账号单选字段中的选项
         * 3、再去接口属性匹配表过滤
         */
        GameAttrTemplate gameAttrTemplate = new GameAttrTemplate();
        gameAttrTemplate.setGameId(goodsInfoAndAttrValueDto.getGameId());
        gameAttrTemplate.setIsEnable("0");
        gameAttrTemplate.setFieldType("radio");
        List<GameAttrTemplate> gameAttrTemplates = gameAttrTemplateMapper.selectGameAttrTemplateList(gameAttrTemplate);
        Field[] declaredFields = goodsInfoAndAttrValueDto.getClass().getDeclaredFields();
        JSONObject propertyList = JSONObject.parseObject(JSONObject.toJSONString(goodsBean.getPropertyList()));

        List<JSONObject> defObjects = new ArrayList<>();
        defObjects.addAll(jsonObjects);
        for (JSONObject object : jsonObjects) {
            for (GameAttrTemplate attrTemplate : gameAttrTemplates) {
                String aavName = attrTemplate.getAavName();
                for (Field declaredField : declaredFields) {
                    String name = declaredField.getName();
                    if (aavName.equals(name)) {
                        //一级属性
                        //注意 YdConfigId 对应的是 f字段对应的 id
                        if (Objects.equals(object.getLong("YdConfigId"), attrTemplate.getId())) {
                            String id = object.getString("id");
                            defObjects.remove(object);//如果匹配上，则去掉
                            String interRadioReqs1 = object.getString("interRadioReqs");
                            List<JSONObject> jsonObjects2 = JSONObject.parseArray(interRadioReqs1, JSONObject.class);
                            declaredField.setAccessible(true);
                            try {
                                //获取选择的值 例如  实名中的可二次
                                Object o = declaredField.get(goodsInfoAndAttrValueDto);
                                String oneValue = String.valueOf(o);
                                List<JSONObject> twoAttr = jsonObjects2.stream().filter(j -> StringUtils.isNotEmpty(j.getString("YdConfigId"))?j.getString("YdConfigId").contains(oneValue):"111".contains(oneValue)).collect(Collectors.toList());
                                String interConfigName = object.getString("InterConfigName");
                                String defaultValue = object.getString("defaultValue");
                                if(StringUtils.isEmpty(defaultValue)&&object.getString("name").equals("段位")){
                                    defaultValue = "暂无段位";
                                }
                                if (org.springframework.util.CollectionUtils.isEmpty(twoAttr)) {
                                    if (StringUtils.isNotEmpty(defaultValue)) {
//                                        mateMap.put("id", InterConfigId);
//                                        mateMap.put("val", defaultValue);
                                        propertyList.put(id, defaultValue);
                                    }
                                }
//                                if (org.springframework.util.CollectionUtils.isEmpty(twoAttr) && StringUtils.isEmpty(defaultValue)) {
//                                    throw new GlobalException("属性" + interConfigName + " 接口要求必传，但是暂未匹配到，请设置默认值");
//                                }
                                if (!org.springframework.util.CollectionUtils.isEmpty(twoAttr)) {
                                    JSONObject jsonObject2 = twoAttr.get(0);
                                    String interConfigId2 = jsonObject2.getString("InterConfigId");
                                    propertyList.put(id, interConfigId2);
                                }
                            } catch (Exception e) {
                                throw new GlobalException("单选项" + attrTemplate.getFieldName() + "匹配错误");
                            }
                        }
                    }
                }
            }
        }
        //开始匹配默认值
        for (JSONObject object : defObjects) {
            String id = object.getString("id");
//            if(StringUtils.isEmpty(InterConfigId)){
//                InterConfigId = object.getString("id");
//            }
            interRadioReqs = object.getString("interRadioReqs");
            jsonObjects = JSONObject.parseArray(interRadioReqs, JSONObject.class);
            for (JSONObject objects : jsonObjects) {
                if(StringUtils.isNotEmpty(objects.getString("defaultValue"))){
                    propertyList.put(id, objects.getString("defaultValue"));
                }
            }
        }
        goodsBean.setPropertyList(propertyList);
        //========================单选属性匹配结束=====================//
    }
    private void builderCheckAttr(GoodsInfoAndAttrValueDto goodsInfoAndAttrValueDto, YX7881GoodsBean goodsBean, String checkAttr) {
        /**
         * 1、先查询自定义中所有多选的字段
         * 2、再查该账号单选字段中的选项
         * 3、再去接口属性匹配表过滤
         */
        Field[] declaredFields = goodsInfoAndAttrValueDto.getClass().getDeclaredFields();
        JSONObject checkAttrJson = JSONObject.parseObject(checkAttr);
        String interCheckBoxReqs = checkAttrJson.getString("interCheckBoxReqs");
        List<JSONObject> checkJsonList = JSONObject.parseArray(interCheckBoxReqs, JSONObject.class);
        if (org.springframework.util.CollectionUtils.isEmpty(checkAttrJson)) {
            throw new GlobalException("接口多选属性暂未配置");
        }

        GameAttrTemplate gameAttrTemplate = new GameAttrTemplate();
        gameAttrTemplate.setGameId(goodsInfoAndAttrValueDto.getGameId());
        gameAttrTemplate.setIsEnable("0");
        List<String> types = new ArrayList<>();
        types.add("checkbox");
        types.add("boxradio");
        gameAttrTemplate.setFieldTypes(types);
        List<GameAttrTemplate> checkAttrTemplates = gameAttrTemplateMapper.selectGameAttrTemplateList(gameAttrTemplate);

        JSONObject propertyList = JSONObject.parseObject(JSONObject.toJSONString(goodsBean.getPropertyList()));

        for (JSONObject object : checkJsonList) {
            String pf_ids = "";
            for (GameAttrTemplate attrTemplate : checkAttrTemplates) {

                String aavName = attrTemplate.getAavName();
                for (Field declaredField : declaredFields) {
                    String name = declaredField.getName();
                    if (aavName.equals(name)) {
                        declaredField.setAccessible(true);

//                        List<String> list2 = new ArrayList<>();
//                        for (String s : split2) {
//                            s = s.replace(" ", "");
//                            list2.add(s);
//                        }
                        Object o = null;
                        try {
                            o = declaredField.get(goodsInfoAndAttrValueDto);
                        } catch (IllegalAccessException e) {
                            throw new GlobalException("多选项" + attrTemplate.getFieldName() + "匹配错误");
                        }
                        String oneValue = String.valueOf(o);
                        String interCheckBoxReqsStr = object.getString("interCheckBoxReqs");
                        //开始匹配二级属性
                        List<JSONObject> jsonObjects2 = JSONObject.parseArray(interCheckBoxReqsStr, JSONObject.class);
                        /**
                         * 咱们的f字段  多选项都是用空格 隔开，用,号切割数组，跟匹配的数据匹配、匹配上说明此账号勾选的有此属性
                         */
                        for (JSONObject jsonObject1 : jsonObjects2) {
                            String[] split1 = oneValue.split(",");
                            String ydConfigId1 = jsonObject1.getString("YdConfigId");
                            for (String s : split1) {
                                if (Objects.equals(s, ydConfigId1)) {
                                    String InterConfigId2 = jsonObject1.getString("id");
                                    pf_ids+=","+InterConfigId2;
                                }
                            }
                        }
                    }
                }
            }
            if (StringUtils.isNotEmpty(pf_ids)) {
                propertyList.put(object.getString("id"), pf_ids.substring(1).trim());
            }
        }
        goodsBean.setPropertyList(propertyList);
    }
    /**
     * 开始匹配输入框属性
     *
     * @param goodsInfoAndAttrValueDto
     * @param inputAttr
     */
    private void builderInputAttr(GoodsInfoAndAttrValueDto goodsInfoAndAttrValueDto, YX7881GoodsBean goodsBean, String inputAttr) {
        JSONObject childPropertyList = new JSONObject();
        JSONObject propertyList = JSONObject.parseObject(JSONObject.toJSONString(goodsBean.getPropertyList()));
        Field[] declaredFields = goodsInfoAndAttrValueDto.getClass().getDeclaredFields();

        //========================开始匹配输入框=====================//
        JSONObject jsonObject1 = JSONObject.parseObject(inputAttr);
        String inputJson = jsonObject1.getString("inputJson");
        List<JSONObject> jsonObjects1 = JSONObject.parseArray(inputJson, JSONObject.class);
        GameAttrTemplate gameAttrTemplate = new GameAttrTemplate();
        gameAttrTemplate.setGameId(goodsInfoAndAttrValueDto.getGameId());
        gameAttrTemplate.setIsEnable("0");
        ArrayList types = new ArrayList<>();
        types.add("number");
        types.add("input");
        gameAttrTemplate.setFieldTypes(types);
        List<GameAttrTemplate> inputTemplates = gameAttrTemplateMapper.selectGameAttrTemplateList(gameAttrTemplate);
        List<JSONObject> defInputObjects = new ArrayList<>();
        defInputObjects.addAll(jsonObjects1);
        for (JSONObject object : jsonObjects1) {
            for (GameAttrTemplate inputTemplate : inputTemplates) {
                JSONObject att = new JSONObject();
                String aavName = inputTemplate.getAavName();
                if (Objects.equals(object.getString("aavName"), inputTemplate.getAavName())) {
                    defInputObjects.remove(object);
                    String aavNameInter = object.getString("interName");
                    String interId = object.getString("interId");
                    for (Field declaredField : declaredFields) {
                        String name = declaredField.getName();
                        if (Objects.equals(aavName, name)) {
                            declaredField.setAccessible(true);
                            Object o = null;
                            try {
                                o = declaredField.get(goodsInfoAndAttrValueDto);
                            } catch (IllegalAccessException e) {
                                throw new GlobalException("3属性参数错误，请匹配后重新配置");
                            }
                            if(Objects.isNull(o)){
                                String fieldType = inputTemplate.getFieldType();
                                if(fieldType.equals("number")){
                                    o = 0;
                                }
                            }
                            String oneValue = String.valueOf(o);
                            if (StringUtils.isNotEmpty(oneValue)) {
                                propertyList.put(interId,oneValue);
                            }
                        }
                    }
                }

            }
        }
        //开始匹配默认值
        for (JSONObject object : defInputObjects) {
            String id = object.getString("id");
            String defaultValue = object.getString("defaultValue");
            if (StringUtils.isNotEmpty(defaultValue)) {
//                mateMap.put("id", InterConfigId);
//                mateMap.put("val", defaultValue);
                propertyList.put(id,defaultValue);
            }
        }
        goodsBean.setPropertyList(propertyList);
    }
    public static String createQQAccount() {
        int num = 8;
        String[] vec = {"0", "1", "2", "3", "4", "5", "6", "7", "8", "9"};
        num = num <= 0 ? 1 : num;
        StringBuffer str = new StringBuffer(10);
        for (int i = 0; i < num; i++) {
            int r1 = Long.valueOf(Math.round(Math.random() * (vec.length - 1))).intValue();
            str.append(vec[r1]);
        }
        return str.toString();
    }
    @Override
    public AjaxResult addGame(GoodsInfoAndAttrValueDto goodsInfoAndAttrValueDto, SalePartner salePartner) {
        goodsInfoAndAttrValueDto.setAccountNumber(createQQAccount());
        if(StringUtils.isNotEmpty(goodsInfoAndAttrValueDto.getCarrierName())) {
            if (goodsInfoAndAttrValueDto.getCarrierName().equals("微信")) {
                goodsInfoAndAttrValueDto.setAccountNumber("asd" + createQQAccount());
            }
        }

        List<YX7881GoodsBean> list = new ArrayList<>();
        YX7881GoodsBean goodsBean = new YX7881GoodsBean();
        if ("王者荣耀".equals(goodsInfoAndAttrValueDto.getGameName())) {
            goodsBean = wzryInfo(goodsInfoAndAttrValueDto, goodsBean);
        } else if ("和平精英".equals(goodsInfoAndAttrValueDto.getGameName())) {
            goodsBean = hpjyInfo(goodsInfoAndAttrValueDto, goodsBean);
        } else if ("英雄联盟".equals(goodsInfoAndAttrValueDto.getGameName())) {
            goodsBean = yxlmInfo(goodsInfoAndAttrValueDto, goodsBean);
        } else if ("穿越火线".equals(goodsInfoAndAttrValueDto.getGameName())) {
            goodsBean = cyhxCFInfo(goodsInfoAndAttrValueDto, goodsBean);
        } else if ("枪战王者".equals(goodsInfoAndAttrValueDto.getGameName())) {
            goodsBean = cyhxQZWZInfo(goodsInfoAndAttrValueDto, goodsBean);
        } else if ("原神".equals(goodsInfoAndAttrValueDto.getGameName())) {
            goodsBean = ysInfo(goodsInfoAndAttrValueDto, goodsBean);
        } else if ("火影忍者".equals(goodsInfoAndAttrValueDto.getGameName())) {
            goodsBean = hyrzInfo(goodsInfoAndAttrValueDto, goodsBean);
        } else if ("英雄联盟(手游)".equals(goodsInfoAndAttrValueDto.getGameName())) {
            goodsBean = yxlmsyInfo(goodsInfoAndAttrValueDto, goodsBean);
        } else if ("无畏契约".equals(goodsInfoAndAttrValueDto.getGameName())) {
            goodsBean = wwqyInfo(goodsInfoAndAttrValueDto, goodsBean);
        } else if ("使命召唤".equals(goodsInfoAndAttrValueDto.getGameName())) {
            goodsBean = smzhm(goodsInfoAndAttrValueDto, goodsBean);
        } else if ("金铲铲之战".equals(goodsInfoAndAttrValueDto.getGameName())) {
            goodsBean = jccInfo(goodsInfoAndAttrValueDto, goodsBean);
        } else if ("永劫无间".equals(goodsInfoAndAttrValueDto.getGameName())) {
            goodsBean = yjwjInfo(goodsInfoAndAttrValueDto, goodsBean);
        } else if ("永劫无间手游".equals(goodsInfoAndAttrValueDto.getGameName())) {
            goodsBean = yjwjsyInfo(goodsInfoAndAttrValueDto, goodsBean);
        } else if ("暗区突围".equals(goodsInfoAndAttrValueDto.getGameName())) {
            goodsBean = aqtwInfo(goodsInfoAndAttrValueDto, goodsBean);
        } else if ("三角洲行动".equals(goodsInfoAndAttrValueDto.getGameName())) {
            goodsBean = sjzxdInfo(goodsInfoAndAttrValueDto, goodsBean);
        } else if ("使命召唤手游".equals(goodsInfoAndAttrValueDto.getGameName())) {
            goodsBean = smzhsyInfo(goodsInfoAndAttrValueDto, goodsBean);
        } else {
            throw new GlobalException("《" + goodsInfoAndAttrValueDto.getGameName() + "》此游戏未对接");
        }

        Property(goodsBean,goodsInfoAndAttrValueDto,salePartner);

        goodsBean.setDeposit(new Short("0"));
        String title = goodsInfoAndAttrValueDto.getDes();
//        title = "【编号:"+goodsInfoAndAttrValueDto.getId()+"】"+title;
        if (Objects.nonNull(title)) {
//            if (title.length() > 100) {
//                title = title.substring(0, 90);
//            }
            goodsBean.setTitle(title);
        } else {
            goodsBean.setTitle("默认标题");
        }
        goodsBean.setGtId("100003");
        goodsBean.setEffective(0);
        goodsBean.setPerNum(new BigDecimal(1));
        goodsBean.setPhone("18888888888");
        goodsBean.setPrice(String.valueOf(goodsInfoAndAttrValueDto.getPrice()));
        goodsBean.setStock(1l);
        goodsBean.setUserId(salePartner.getThreeOther().split(",")[0]);
        goodsBean.setTradeTime("00:00-24:00");
        goodsBean.setDescription(goodsInfoAndAttrValueDto.getDes());
        goodsBean.setThirdGoodsId(String.valueOf(goodsInfoAndAttrValueDto.getThirdId()));

//        if(supplyInfo.getUserId()==611) {
//            goodsBean.setCompensationType("1");
//        }
//        if(salePartner.getSaleKey().equals("renYiGame")){
//            goodsBean.setCompensationType("1");
//        }
//        if(salePartner.getName().equals("冷酷网游---7881")){
//            goodsBean.setCompensationType("1");
//        }
//        if(salePartner.getSaleKey().equals("tianchen")){
//
//        }
        goodsBean.setCompensationType("1");
        List<String> imgSet = new ArrayList<>();
        if (Objects.nonNull(goodsInfoAndAttrValueDto.getTitleImg())) {
            imgSet.add(goodsInfoAndAttrValueDto.getTitleImg());
        }
        List<Map<String, Object>> urlArr = goodsInfoAndAttrValueDto.getUrlArr();
        List<String> infoImgs = new ArrayList<>();
        if(StringUtils.isNotEmpty(goodsInfoAndAttrValueDto.getTitleImg())){
            infoImgs.add(goodsInfoAndAttrValueDto.getTitleImg());
        }
        for(Map<String, Object> maps : urlArr){
            String ss = String.valueOf(maps.get("url"));
            infoImgs.add(ss);
        }
        if (!CollectionUtils.isEmpty(infoImgs)) {
            for (String img : infoImgs) {
                if(!img.equals(goodsInfoAndAttrValueDto.getTitleImg())) {
                    imgSet.add(img);
                }
            }
        }
        goodsBean.setImages(imgSet.toArray(new String[imgSet.size()]));
        list.add(goodsBean);
        ResultEntity resultEntity = null;
        try {
            resultEntity = LieBaoCore.publish(list, salePartner);
        } catch (Exception e) {
            e.printStackTrace();
        }
        log.info("7881请求参数: " + JSONObject.toJSONString(list));
        log.info("7881返回参数: " + JSONObject.toJSONString(resultEntity));

        Map<String, Object> result = new HashMap<>();
        if (resultEntity != null) {
            if (!"SUCCESS".equals(resultEntity.getCode())) {
                result.put("code", 500);
            } else {
                result.put("code", 200);
                String reaccount_id = ((String) resultEntity.getData()).replace("[", "").replace("]", "");
                result.put("outId", reaccount_id);
            }
            result.put("msg", resultEntity.getMsg());
        }
        result.put("req", JSONObject.toJSONString(list));
        result.put("res", resultEntity);
        return AjaxResult.success(result);
    }

    @Override
    public AjaxResult editGame(GoodsInfoAndAttrValueDto goodsInfoAndAttrValueDto,
                               SalePartner salePartner) {
        List<EditGoodsBean> editData = new ArrayList<>();
        EditGoodsBean editGoodsBean = new EditGoodsBean();
        ArtRec artRecreq = new ArtRec();
        artRecreq.setConfig(salePartner.getId());
        artRecreq.setAccountId(goodsInfoAndAttrValueDto.getId());
        List<ArtRec> artRecs = artRecMapper.selectArtRecList(artRecreq);
        editGoodsBean.setGoodsId(artRecs.get(0).getOutid());
        editGoodsBean.setPrice(goodsInfoAndAttrValueDto.getPrice().doubleValue());
        editGoodsBean.setStock("1");
        editGoodsBean.setUserId(salePartner.getThreeOther().split(",")[0]);
        editData.add(editGoodsBean);
        Map<String, Object> result = new HashMap<>();
        ResultEntity resultEntity = null;
        try {
            resultEntity = LieBaoCore.edit(editData, salePartner);
        } catch (Exception e) {
            e.printStackTrace();
        }
        log.info("7881编辑请求参数: " + JSONObject.toJSONString(editData));
        if(Objects.nonNull(resultEntity)) {
            log.info("7881编辑返回参数: " + JSONObject.toJSONString(resultEntity));
            if ("SUCCESS".equals(resultEntity.getCode())) {
                result.put("code", 200);
            } else {
                result.put("code", 500);
            }
        }else{
            result.put("code", 500);
        }
        result.put("req", JSONObject.toJSONString(editData));
        result.put("res", resultEntity);
        if (resultEntity != null) {
            result.put("msg", resultEntity.getData());
        }
        return AjaxResult.success(result);
    }

    @Override
    public AjaxResult delGame(GoodsInfoAndAttrValueDto goodsInfoAndAttrValueDto, SalePartner salePartner) {
        ArtRec artRecreq = new ArtRec();
        artRecreq.setConfig(salePartner.getId());
        artRecreq.setAccountId(goodsInfoAndAttrValueDto.getId());
        List<ArtRec> artRecs = artRecMapper.selectArtRecList(artRecreq);
        Long account_id = Long.valueOf(artRecs.get(0).getOutid());
        Map<String, Object> result = new HashMap<>();
        try {
            ResultEntity resultXJ = shangpinxiajia(account_id, salePartner);  //商品下架
            ResultEntity resultSC = shangpinshanchu(account_id, salePartner);  //商品删除
            if(Objects.isNull(resultSC.getData())){
                throw new GlobalException("7881返回结果为空!!!"+resultSC.getMsg());
            }
            String dataSC = resultSC.getData().toString();

            log.info("7881下架请求参数: " + account_id);
            log.info("7881下架返回参数: " + JSONObject.toJSONString(resultXJ));
            log.info("7881删除返回参数: " + JSONObject.toJSONString(resultSC));
            if ("SUCCESS".equals(resultSC.getCode()) && StringUtils.equals(dataSC, "[]")) {
                result.put("code", 200);
            } else {
                result.put("code", 500);
            }
            result.put("res", resultSC);
            result.put("msg", dataSC);

        } catch (Exception e) {
            e.printStackTrace();
        }
        return AjaxResult.success(result);
    }

    /**
     * 通用 比对方法 取第一个并返回
     *
     * @param str1
     * @param str2
     * @return
     */
    String biGetFirst(String str1, String str2) {
        String res = "";
        if (StringUtils.isEmpty(str2)) {
            return res;
        }
        String[] str1sz = str1.split(",");
        for (String s : str1sz) {
            if (str2.replace("贵族", "V").toUpperCase().replace("IP", "").contains(s)) {
                res = s;
                break;
            }
        }
        return res;
    }

    /**
     * 英雄联盟 段位 比对方法 取第一个并返回 为了不跟其他游戏比较相互影响单拉出来
     *
     * @param str1
     * @param str2
     * @return
     */
    String yxlmdwbiGetFirst(String str1, String str2) {
        //黑铁,黄铜,白银,黄金,铂金,钻石,大师,宗师,王者
        String res = "";
        if (StringUtils.isEmpty(str2)) {
            return res;
        }
        String[] str1sz = str1.split(",");
        for (String s : str1sz) {
            String a = s;
            if (str2.contains(a)) {
                res = s;
                break;
            }
        }
        return res;
    }

    /**
     * 通用 比对方法 比对成功加上
     *
     * @param str1
     * @param str2
     * @return
     */
    String biGetAll(String str1, String str2) {
        String res = "";
        if (StringUtils.isEmpty(str2)) {
            return res;
        }
        String[] str1sz = str1.split(",");
        boolean is = false;
        for (String s : str1sz) {
            if (str2.replace("·", "")
                    .replace("(", "")
                    .replace(")", "")
                    .replace("角色-", "").contains(s.replace("·", "")
                            .replace("(", "")
                            .replace(")", "")
                            .replace("角色-", ""))) {
                res = res + "," + s;
            }
        }
        if (res.length() > 0) {
            res = res.replaceFirst(",", "");
        }
        return res;
    }

    /**
     * 穿越火线端游 比对方法 比对成功加上 为了不跟其他游戏比较相互影响单拉出来
     *
     * @param str1
     * @param str2
     * @return
     */
    String CyhxCFbiGetAll(String str1, String str2) {
        String res = "";
        if (StringUtils.isEmpty(str2)) {
            return res;
        }
        String[] str1sz = str1.split(",");
        boolean is = false;
        for (String s : str1sz) {
            if (str2.replace("·", "")
                    .replace("(", "")
                    .replace(")", "")
                    .replace("-", "")
                    .contains(s.replace("·", "")
                            .replace("(", "")
                            .replace(")", "")
                            .replace("-", ""))) {
                res = res + "," + s;
            }
        }
        if (res.length() > 0) {
            res = res.replaceFirst(",", "");
        }
        return res;
    }

    /**
     * 根据游戏id获取该游戏信息
     *
     * @param gameid
     */
    static void getGameInfo(String gameid, SalePartner salePartner) {
        String gtId = "100003";
        String result = null;
        try {
            result = LieBaoCore.get_game_info(gameid, salePartner);
        } catch (Exception e) {
            e.printStackTrace();
        }
        log.info(result);
    }


    /**
     * 根据游戏id获取该游戏垂直属性
     *
     * @param gameid
     */
    static void getGameVertiacl(String gameid, SalePartner salePartner) {
        String gtId = "100003";
        String result = null;
        try {
            result = LieBaoCore.get_gamegt_vertical(gameid, gtId, salePartner);
        } catch (Exception e) {
            e.printStackTrace();
        }
        log.info(result);
    }

    /**
     * 根据商品id进行下架
     *
     * @param goodsId
     * @param salePartner
     * @return
     * @throws Exception
     */
    ResultEntity shangpinxiajia(Long goodsId, SalePartner salePartner) throws Exception {
//        Map params = new HashMap<>();
//        params.put("goodsId", goodsId);
//        params.put("userId", salePartner.getThreeOther());
//        params.put("enforce", "true");
//        params.put("closedReason", "0");
//        ResultEntity resultEntity = LieBaoCore.cp_goods_pull_off(params, salePartner);
        String url = LieBaoCore.LIEBAO_URL + "/cp/" + salePartner.getThreeOther().split(",")[1]+ "/goods/pull_off?userId=" + salePartner.getThreeOther().split(",")[0] +
                "&goodsId=" + goodsId + "&enforce=true&closedReason=0";


        String result = HttpUtil.doGet(url, null, LieBaoUtil.getHearder(LieBaoCore.X_SERVICE_APP,
                LieBaoCore.SECRET_KEY, ""));

        return JSON.parseObject(result, new TypeReference<ResultEntity>() {
        });
    }

    /**
     * 根据商品id进行删除
     *
     * @param goodsId
     * @param salePartner
     * @return
     * @throws Exception
     */
    ResultEntity shangpinshanchu(Long goodsId, SalePartner salePartner) throws Exception {
//        Map params = new HashMap<>();
//        params.put("goodsId", goodsId);
//        params.put("userId", salePartner.getThreeOther());
//        ResultEntity resultEntity = LieBaoCore.cp_goods_delete(params, salePartner);
        String url = LieBaoCore.LIEBAO_URL + "/cp/" + salePartner.getThreeOther().split(",")[1] + "/goods/delete?userId=" + salePartner.getThreeOther().split(",")[0] +
                "&goodsId=" + goodsId;

        String result = HttpUtil.postRequest(url, null, null, "", LieBaoUtil.getHearder(LieBaoCore.X_SERVICE_APP,
                LieBaoCore.SECRET_KEY, ""));

        if (org.apache.commons.lang3.StringUtils.isEmpty(result)) {

            throw new GlobalException("返回为空");
        }

        return JSON.parseObject(result, new TypeReference<ResultEntity>() {
        });
    }


    /**
     * 封装 王者荣耀 信息
     *
     * @param goodsInfoAndAttrValueDto
     * @param goodsBean
     * @return
     */
    YX7881GoodsBean wzryInfo(GoodsInfoAndAttrValueDto goodsInfoAndAttrValueDto, YX7881GoodsBean goodsBean) {
        WzryInfo wzryInfo = new WzryInfo();
        switch (goodsInfoAndAttrValueDto.getSystemName() + goodsInfoAndAttrValueDto.getCarrierName()) {
            case "安卓QQ":
                goodsBean.setGameId("A2775");
                goodsBean.setCarrierId("A2775B001");
                goodsBean.setCarriername("QQ");
                goodsBean.setGroupId("A2775P003");
                goodsBean.setServerId("A2775P003001");
                wzryInfo.setCode7("正式服");
                break;
            case "安卓微信":
                goodsBean.setGameId("A2775");
                goodsBean.setCarrierId("A2775B002");
                goodsBean.setCarriername("微信");
                goodsBean.setGroupId("A2775P034");
                goodsBean.setServerId("A2775P034001");
                wzryInfo.setCode7("正式服");
                break;
            case "苹果QQ":
                goodsBean.setGameId("A2705");
                goodsBean.setCarrierId("A2705Y002");
                goodsBean.setCarriername("QQ");
                goodsBean.setGroupId("A2705P003");
                goodsBean.setServerId("A2705P003001");
                wzryInfo.setCode8("正式服");
                break;
            case "苹果微信":
                goodsBean.setGameId("A2705");
                goodsBean.setCarrierId("A2705Y003");
                goodsBean.setCarriername("微信");
                goodsBean.setGroupId("A2705P011");
                goodsBean.setServerId("A2705P011001");
                wzryInfo.setCode8("正式服");
                break;
        }
        //账号 y
        wzryInfo.setGameaccount(goodsInfoAndAttrValueDto.getAccountNumber().trim());
        //密码 y
        wzryInfo.setGamepassword("a123456");
        goodsBean.setPropertyList(wzryInfo);
        return goodsBean;
    }

    /**
     * 封装 和平精英 信息
     *
     * @param goodsInfoAndAttrValueDto
     * @param goodsBean
     * @return
     */
    YX7881GoodsBean hpjyInfo(GoodsInfoAndAttrValueDto goodsInfoAndAttrValueDto, YX7881GoodsBean goodsBean) {
        HpjyInfo hpjyInfo = new HpjyInfo();
        switch (goodsInfoAndAttrValueDto.getSystemName() + goodsInfoAndAttrValueDto.getCarrierName()) {
            case "安卓QQ":
                goodsBean.setGameId("A5454");
                goodsBean.setCarrierId("A5454Y002");
                goodsBean.setCarriername("QQ");
                goodsBean.setGroupId("A5454P001");
                goodsBean.setServerId("A5454P001001");
                break;
            case "安卓微信":
                goodsBean.setGameId("A5454");
                goodsBean.setCarrierId("A5454Y001");
                goodsBean.setCarriername("微信");
                goodsBean.setGroupId("A5454P002");
                goodsBean.setServerId("A5454P002001");
                break;
            case "苹果QQ":
                goodsBean.setGameId("A5455");
                goodsBean.setCarrierId("A5455Y002");
                goodsBean.setCarriername("QQ");
                goodsBean.setGroupId("A5455P001");
                goodsBean.setServerId("A5455P001001");
                break;
            case "苹果微信":
                goodsBean.setGameId("A5455");
                goodsBean.setCarrierId("A5455Y001");
                goodsBean.setCarriername("微信");
                goodsBean.setGroupId("A5455P002");
                goodsBean.setServerId("A5455P002001");
                break;
        }
        //账号 y
        hpjyInfo.setGameaccount(goodsInfoAndAttrValueDto.getAccountNumber().trim());
        if(goodsInfoAndAttrValueDto.getCarrierName().equals("微信")){
            hpjyInfo.setGameaccount("asd"+goodsInfoAndAttrValueDto.getAccountNumber().trim());
        }
        //密码 y
        hpjyInfo.setGamepassword("a123456");
        goodsBean.setPropertyList(hpjyInfo);
        return goodsBean;
    }

    /**
     * 封装 英雄联盟端游 信息
     *
     * @param goodsInfoAndAttrValueDto
     * @param goodsBean
     * @return
     */
    YX7881GoodsBean yxlmInfo(GoodsInfoAndAttrValueDto goodsInfoAndAttrValueDto, YX7881GoodsBean goodsBean) {
        goodsBean.setGameId("G603");
        YxlmInfo yxlmInfo = new YxlmInfo();
        //区服
        String yxlmqf = "峡谷之巅=G603P005002--G603P005,班德尔城=G603P001004--G603P001,日服=G603P006006--G603P006,均衡教派=G603P001013--G603P001,钢铁烈阳=G603P001012--G603P001,扭曲丛林=G603P002006--G603P002,欧服=G603P006002--G603P006,皮城警备=G603P001020--G603P001,试炼之地=G603P003001--G603P003,征服之海=G603P001018--G603P001,黑色玫瑰=G603P001010--G603P001,巨神峰=G603P001007--G603P001,水晶之痕=G603P001014--G603P001,韩服=G603P006001--G603P006,台服=G603P006005--G603P006,弗雷尔卓德=G603P002003--G603P002,无畏先锋=G603P002004--G603P002,皮尔特沃夫=G603P001005--G603P001,战争学院=G603P001006--G603P001,雷瑟守备=G603P001008--G603P001,艾欧尼亚=G603P001001--G603P001,恕瑞玛=G603P002005--G603P002,教育网专区=G603P001015--G603P001,暗影岛=G603P001011--G603P001,卡拉曼达=G603P001019--G603P001,男爵领域=G603P005001--G603P005,美服=G603P006003--G603P006,裁决之地=G603P001009--G603P001,守望之海=G603P001017--G603P001,澳服=G603P006004--G603P006,巨龙之巢=G603P002007--G603P002,诺克萨斯=G603P001003--G603P001,德玛西亚=G603P002002--G603P002,影流=G603P001016--G603P001,祖安=G603P001002--G603P001,比尔吉沃特=G603P002001--G603P002";

        Map qdqMap = stringTOmap(yxlmqf);
        if (Objects.nonNull(qdqMap.get(goodsInfoAndAttrValueDto.getServerName()))) {
            String qu = qdqMap.get(goodsInfoAndAttrValueDto.getServerName()).toString();
            goodsBean.setGroupId(qu.split("--")[1].trim());
            goodsBean.setServerId(qu.split("--")[0].trim());
        } else {
            throw new GlobalException(goodsInfoAndAttrValueDto.getThirdId() + "英雄联盟大区未找到");
        }
        yxlmInfo.setGameaccount(goodsInfoAndAttrValueDto.getAccountNumber().trim());
        //密码 y
        yxlmInfo.setGamepassword("a123456");
        yxlmInfo.setCode13("未定级");
        yxlmInfo.setLevel("30");
        goodsBean.setPropertyList(yxlmInfo);
        return goodsBean;
    }

    /**
     * 封装 穿越火线端游 信息
     *
     * @param goodsInfoAndAttrValueDto
     * @param goodsBean
     * @return
     */
    YX7881GoodsBean cyhxCFInfo(GoodsInfoAndAttrValueDto goodsInfoAndAttrValueDto, YX7881GoodsBean goodsBean) {
        goodsBean.setGameId("G68");
        String cyhxCFQF = "浙江二区=G68P001020--G68P001,安徽一区=G68P001019--G68P001,北京四区=G68P002007--G68P002,上海二区=G68P001009--G68P001,湖南二区=G68P006009--G68P006,江苏二区=G68P001024--G68P001,湖北二区=G68P006002--G68P006,广东二区=G68P006004--G68P006,辽宁三区=G68P002005--G68P002,山东二区=G68P002015--G68P002,湖南一区=G68P006008--G68P006,河南一区=G68P002009--G68P002,湖北一区=G68P006001--G68P006,广东一区=G68P006003--G68P006,北京二区=G68P002003--G68P002,河北一区=G68P002013--G68P002,广东四区=G68P006006--G68P006,广西一区=G68P006011--G68P006,北京一区=G68P002002--G68P002,云南一区=G68P005005--G68P005,河南二区=G68P002016--G68P002,南方大区=G68P006007--G68P006,陕西一区=G68P005001--G68P005,重庆一区=G68P005002--G68P005,辽宁一区=G68P002001--G68P002,移动专区=G68P001025--G68P001,吉林一区=G68P002012--G68P002,辽宁二区=G68P002004--G68P002,教育网专区=G68P001026--G68P001,江西一区=G68P006010--G68P006,广东三区=G68P006005--G68P006,北京三区=G68P002006--G68P002,山东一区=G68P002010--G68P002,江苏一区=G68P001018--G68P001,福建一区=G68P001001--G68P001,浙江一区=G68P001002--G68P001,黑龙江区=G68P002011--G68P002,四川二区=G68P005004--G68P005,上海一区=G68P001008--G68P001,四川一区=G68P005003--G68P005,北方大区=G68P002008--G68P002,山西一区=G68P002014--G68P002";
        Map cyhxCFQFMap = stringTOmap(cyhxCFQF);
        if (Objects.nonNull(cyhxCFQFMap.get(goodsInfoAndAttrValueDto.getServerName()))) {
            String qu = cyhxCFQFMap.get(goodsInfoAndAttrValueDto.getServerName()).toString();
            goodsBean.setGroupId(qu.split("--")[1].trim());
            goodsBean.setServerId(qu.split("--")[0].trim());
        } else {
            throw new GlobalException(goodsInfoAndAttrValueDto.getThirdId() + "英雄联盟大区未找到");
        }
        CyhxCFInfo cyhxCFInfo = new CyhxCFInfo();
        cyhxCFInfo.setGameaccount(goodsInfoAndAttrValueDto.getAccountNumber().trim());
        //密码 y
        cyhxCFInfo.setGamepassword("a123456");
        goodsBean.setPropertyList(cyhxCFInfo);
        return goodsBean;
    }

    /**
     * 封装 穿越火线手游 信息
     *
     * @param goodsInfoAndAttrValueDto
     * @param goodsBean
     * @return
     */
    YX7881GoodsBean cyhxQZWZInfo(GoodsInfoAndAttrValueDto goodsInfoAndAttrValueDto, YX7881GoodsBean goodsBean) {
        CyhxQZWZInfo cyhxQZWZInfo = new CyhxQZWZInfo();
        goodsBean.setGameId("A5430");
        switch (goodsInfoAndAttrValueDto.getSystemName() + goodsInfoAndAttrValueDto.getCarrierName()) {
            case "安卓QQ":
                goodsBean.setCarrierId("A5430Y003");
                goodsBean.setCarriername("安卓QQ");
                goodsBean.setGroupId("A5430P002");
                goodsBean.setServerId("A5430P002001");
                break;
            case "安卓微信":
                goodsBean.setCarrierId("A5430Y004");
                goodsBean.setCarriername("安卓微信");
                goodsBean.setGroupId("A5430P004");
                goodsBean.setServerId("A5430P004001");
                break;
            case "苹果QQ":
                goodsBean.setCarrierId("A5430Y005");
                goodsBean.setCarriername("苹果QQ");
                goodsBean.setGroupId("A5430P001");
                goodsBean.setServerId("A5430P001001");
                break;
            case "苹果微信":
                goodsBean.setCarrierId("A5430Y006");
                goodsBean.setCarriername("苹果微信");
                goodsBean.setGroupId("A5430P003");
                goodsBean.setServerId("A5430P003001");
                break;
        }

        cyhxQZWZInfo.setGameaccount(goodsInfoAndAttrValueDto.getAccountNumber().trim());
        cyhxQZWZInfo.setGamepassword(goodsInfoAndAttrValueDto.getAccountPassword());
        cyhxQZWZInfo.setGamepasswordqr(goodsInfoAndAttrValueDto.getAccountPassword());
        goodsBean.setPropertyList(cyhxQZWZInfo);
        return goodsBean;
    }

    /**
     * 封装 原神 信息
     *
     * @param goodsInfoAndAttrValueDto
     * @param goodsBean
     * @return
     */
    YX7881GoodsBean ysInfo(GoodsInfoAndAttrValueDto goodsInfoAndAttrValueDto, YX7881GoodsBean goodsBean) {
        goodsBean.setGameId("A5653");
        switch (goodsInfoAndAttrValueDto.getServerName()) {
            case "天空岛":
                goodsBean.setCarrierId("A5653Y001");
                goodsBean.setCarriername("游戏官方");
                goodsBean.setGroupId("A5653P001");
                goodsBean.setServerId("A5653P001001");
                break;
            case "世界树":
                goodsBean.setCarrierId("A5653Y002");
                goodsBean.setCarriername("哔哩哔哩");
                goodsBean.setGroupId("A5653P002");
                goodsBean.setServerId("A5653P002001");
                break;
        }
        YsInfo ysInfo = new YsInfo();
        ysInfo.setGameaccount(goodsInfoAndAttrValueDto.getAccountNumber().trim());
        ysInfo.setGamepassword(goodsInfoAndAttrValueDto.getAccountPassword());
        ysInfo.setGamepasswordqr(goodsInfoAndAttrValueDto.getAccountPassword());
        goodsBean.setPropertyList(ysInfo);
        return goodsBean;
    }
    YX7881GoodsBean wwqyInfo(GoodsInfoAndAttrValueDto goodsInfoAndAttrValueDto, YX7881GoodsBean goodsBean) {
        goodsBean.setGameId("G5706");

        goodsBean.setCarrierId("G5706B001");
        goodsBean.setCarriername("QQ账号");

        goodsBean.setGroupId("G5706P001");
        goodsBean.setServerId("G5706P001001");

        goodsBean.setGroupId("G5706P001");
        goodsBean.setServerId("G5706P001001");
        WwqyInfo wwqyInfo = new WwqyInfo();
        wwqyInfo.setAccountType(goodsInfoAndAttrValueDto.getGroupName()+"账号");
        wwqyInfo.setAccountSource("我是号主");
        wwqyInfo.setAntiaddiction("无防沉迷");
        wwqyInfo.setGameaccount(StringUtils.isNotEmpty(goodsInfoAndAttrValueDto.getAccountNumber())?goodsInfoAndAttrValueDto.getAccountNumber():String.valueOf(System.currentTimeMillis()).substring(3));
        wwqyInfo.setGamepassword(String.valueOf(System.currentTimeMillis()).substring(3));
        goodsBean.setPropertyList(wwqyInfo);
        return goodsBean;
    }
    YX7881GoodsBean smzhsyInfo(GoodsInfoAndAttrValueDto goodsInfoAndAttrValueDto, YX7881GoodsBean goodsBean) {
        goodsBean.setGameId("A5403");
        SmzhsyInfo smzhsyInfo = new SmzhsyInfo();
        switch (goodsInfoAndAttrValueDto.getCarrierName()) {
            case "QQ":
                goodsBean.setCarrierId("A5403B001");
                goodsBean.setCarriername("QQ");
                goodsBean.setGroupId("A5403P002");
                goodsBean.setServerId("A5403P002001");
                break;
            case "微信":
                goodsBean.setCarrierId("A5403B002");
                goodsBean.setCarriername("微信");
                goodsBean.setGroupId("A5403P003");
                goodsBean.setServerId("A5403P003001");
                break;
        }
        smzhsyInfo.setGameaccount(goodsInfoAndAttrValueDto.getAccountNumber());
        smzhsyInfo.setGamepassword(String.valueOf(System.currentTimeMillis() / 1000));
        smzhsyInfo.setGamepassword(String.valueOf(System.currentTimeMillis() / 1000));
        goodsBean.setPropertyList(smzhsyInfo);
        return goodsBean;
    }
    YX7881GoodsBean sjzxdInfo(GoodsInfoAndAttrValueDto goodsInfoAndAttrValueDto, YX7881GoodsBean goodsBean) {
        goodsBean.setGameId("A5776");
        SjzxdInfo sjzxdInfo = new SjzxdInfo();
        switch (goodsInfoAndAttrValueDto.getCarrierName()) {
            case "QQ":
                goodsBean.setCarrierId("A5776Y006");
                goodsBean.setCarriername("QQ");
                goodsBean.setGroupId("A5776P001");
                goodsBean.setServerId("A5776P001001");
                break;
            case "微信":
                goodsBean.setCarrierId("A5776Y007");
                goodsBean.setCarriername("微信");
                goodsBean.setGroupId("A5776P001");
                goodsBean.setServerId("A5776P001001");
                break;
        }
        sjzxdInfo.setGameaccount(goodsInfoAndAttrValueDto.getAccountNumber());
        sjzxdInfo.setGamepassword(String.valueOf(System.currentTimeMillis() / 1000));
        sjzxdInfo.setGamepassword(String.valueOf(System.currentTimeMillis() / 1000));
        goodsBean.setPropertyList(sjzxdInfo);
        return goodsBean;
    }
    YX7881GoodsBean aqtwInfo(GoodsInfoAndAttrValueDto goodsInfoAndAttrValueDto, YX7881GoodsBean goodsBean) {
        goodsBean.setGameId("A5692");
        AqtwInfo aqtwInfo = new AqtwInfo();
        switch (goodsInfoAndAttrValueDto.getSystemName() + goodsInfoAndAttrValueDto.getCarrierName()) {
            case "安卓QQ":
                goodsBean.setCarrierId("A5692Y004");
                goodsBean.setCarriername("安卓QQ");
                goodsBean.setGroupId("A5692P001");
                goodsBean.setServerId("A5692P001001");
                break;
            case "安卓微信":
                goodsBean.setCarrierId("A5692Y005");
                goodsBean.setCarriername("安卓微信");
                goodsBean.setGroupId("A5692P002");
                goodsBean.setServerId("A5692P002001");
                break;
            case "苹果QQ":
                goodsBean.setCarrierId("A5692Y006");
                goodsBean.setCarriername("苹果QQ");
                goodsBean.setGroupId("A5692P003");
                goodsBean.setServerId("A5692P003001");
                break;
            case "苹果微信":
                goodsBean.setCarrierId("A5692Y007");
                goodsBean.setCarriername("苹果微信");
                goodsBean.setGroupId("A5692P004");
                goodsBean.setServerId("A5692P004001");
                break;
        }

        aqtwInfo.setGameaccount(goodsInfoAndAttrValueDto.getAccountNumber());
        aqtwInfo.setGamepassword(String.valueOf(System.currentTimeMillis() / 1000));
        aqtwInfo.setGamepassword(String.valueOf(System.currentTimeMillis() / 1000));
        goodsBean.setPropertyList(aqtwInfo);
        return goodsBean;
    }
    YX7881GoodsBean yjwjsyInfo(GoodsInfoAndAttrValueDto goodsInfoAndAttrValueDto, YX7881GoodsBean goodsBean) {
        goodsBean.setGameId("A5741");
        goodsBean.setCarrierId("A5741Y001");
        goodsBean.setGroupId("0");
        goodsBean.setServerId("0");
        YjwjSyInfo yjwjSyInfo = new YjwjSyInfo();
        yjwjSyInfo.setGameaccount(goodsInfoAndAttrValueDto.getAccountNumber());
        yjwjSyInfo.setGamepassword(String.valueOf(System.currentTimeMillis() / 1000));
        yjwjSyInfo.setGamepassword(String.valueOf(System.currentTimeMillis() / 1000));
        goodsBean.setPropertyList(yjwjSyInfo);
        return goodsBean;
    }
    YX7881GoodsBean yjwjInfo(GoodsInfoAndAttrValueDto goodsInfoAndAttrValueDto, YX7881GoodsBean goodsBean) {
        goodsBean.setGameId("G5662");
        goodsBean.setCarrierId("G5662Y001");
        goodsBean.setCarriername("QQ");
        if (goodsInfoAndAttrValueDto.getGroupName().equals("网易")) {
            goodsBean.setGroupId("G5662P001");
            if(goodsInfoAndAttrValueDto.getServerName().contains("手机")) {
                goodsBean.setServerId("G5662P001003");
            }else {
                goodsBean.setServerId("G5662P001002");
            }
        } else if (goodsInfoAndAttrValueDto.getGroupName().equals("Steam")) {
            goodsBean.setGroupId("G5662P002");
            goodsBean.setServerId("G5662P002002");
        } else {
            goodsBean.setGroupId("G5662P003");
            goodsBean.setServerId("G5662P003001");
        }
        YjwjInfo yjwjInfo = new YjwjInfo();
        yjwjInfo.setGameaccount(goodsInfoAndAttrValueDto.getAccountNumber());
        yjwjInfo.setGamepassword("123456");
        yjwjInfo.setGamepasswordqr("123456");
        yjwjInfo.setZhlx(goodsInfoAndAttrValueDto.getServerName().replace("网易",""));
        yjwjInfo.setAwe("青铜");
        goodsBean.setPropertyList(yjwjInfo);
        return goodsBean;
    }
    private YX7881GoodsBean jccInfo(GoodsInfoAndAttrValueDto goodsInfoAndAttrValueDto, YX7881GoodsBean goodsBean) {
        JcczzInfo jcczzInfo = new JcczzInfo();
        goodsBean.setGameId("A5661");
        switch (goodsInfoAndAttrValueDto.getSystemName() + goodsInfoAndAttrValueDto.getCarrierName()) {
            case "安卓QQ":
                goodsBean.setCarrierId("A5661Y001");
                goodsBean.setCarriername("QQ");
                goodsBean.setGroupId("A5661P004");
                goodsBean.setServerId("0");
                break;
            case "安卓微信":
                goodsBean.setCarrierId("A5661Y002");
                goodsBean.setCarriername("微信");
                goodsBean.setGroupId("A5661P005");
                goodsBean.setServerId("A5661P005002");
                break;
            case "苹果QQ":
                goodsBean.setCarrierId("A5661Y001");
                goodsBean.setCarriername("QQ");
                goodsBean.setGroupId("A5661P002");
                goodsBean.setServerId("A5661P002001");
                break;
            case "苹果微信":
                goodsBean.setCarrierId("A5661Y002");
                goodsBean.setCarriername("微信");
                goodsBean.setGroupId("A5661P003");
                goodsBean.setServerId("A5661P003002");
                break;
        }
        goodsBean.setServerId("0");

        String des = goodsInfoAndAttrValueDto.getDes();
        jcczzInfo.setGameaccount(goodsInfoAndAttrValueDto.getAccountNumber());
        jcczzInfo.setGamepassword("wenkefu");
        jcczzInfo.setGamepasswordqr("wenkefu");

        goodsBean.setPropertyList(jcczzInfo);
        return goodsBean;
    }
    YX7881GoodsBean smzhm(GoodsInfoAndAttrValueDto goodsInfoAndAttrValueDto, YX7881GoodsBean goodsBean) {
        JSONObject param = new JSONObject();

        switch (goodsInfoAndAttrValueDto.getSystemName() + goodsInfoAndAttrValueDto.getCarrierName()) {
            case "安卓QQ":
                goodsBean.setGameId("A5403");
                goodsBean.setCarrierId("A5403B001");
                goodsBean.setCarriername("QQ");
                goodsBean.setGroupId("A5403P002");
                goodsBean.setServerId("A5403P002001");
                param.put("code7", "正式服");
                break;
            case "安卓微信":
                goodsBean.setGameId("A5403");
                goodsBean.setCarrierId("A5403B002");
                goodsBean.setCarriername("微信");
                goodsBean.setGroupId("A5403P003");
                goodsBean.setServerId("A5403P003001");
                param.put("code7", "正式服");
                break;
            case "苹果QQ":
                goodsBean.setGameId("A5403");
                goodsBean.setCarrierId("A5403B001");
                goodsBean.setCarriername("QQ");
                goodsBean.setGroupId("A5403P004");
                goodsBean.setServerId("A5403P004001");
                param.put("code7", "正式服");
                break;
            case "苹果微信":
                goodsBean.setGameId("A5403");
                goodsBean.setCarrierId("A5403B002");
                goodsBean.setCarriername("微信");
                goodsBean.setGroupId("A5403P005");
                goodsBean.setServerId("A5403P005001");
                param.put("code7", "正式服");
                break;
        }
        goodsBean.setPropertyList(param);
        return goodsBean;
    }
    YX7881GoodsBean yxlmsyInfo(GoodsInfoAndAttrValueDto goodsInfoAndAttrValueDto, YX7881GoodsBean goodsBean) {
        goodsBean.setGameId("A5654");
        switch (goodsInfoAndAttrValueDto.getSystemName() + goodsInfoAndAttrValueDto.getCarrierName()) {
            case "安卓QQ":
                goodsBean.setCarrierId("A5654Y004");
                goodsBean.setCarriername("QQ");
                goodsBean.setGroupId("A5654P004");
                goodsBean.setServerId("A5654P004001");
                break;
            case "安卓微信":
                goodsBean.setCarrierId("A5654Y003");
                goodsBean.setCarriername("微信");
                goodsBean.setGroupId("A5654P006");
                goodsBean.setServerId("A5654P006001");
                break;
            case "苹果QQ":
                goodsBean.setCarrierId("A5654Y006");
                goodsBean.setCarriername("QQ");
                goodsBean.setGroupId("A5654P005");
                goodsBean.setServerId("A5654P005001");
                break;
            case "苹果微信":
                goodsBean.setCarrierId("A5654Y005");
                goodsBean.setCarriername("微信");
                goodsBean.setGroupId("A5654P007");
                goodsBean.setServerId("A5654P007001");
                break;
        }
        YxlmsyInfo yxlmsyInfo = new YxlmsyInfo();
        yxlmsyInfo.setGameaccount(StringUtils.isNotEmpty(goodsInfoAndAttrValueDto.getAccountNumber())?goodsInfoAndAttrValueDto.getAccountNumber():goodsInfoAndAttrValueDto.getId()+"");
        yxlmsyInfo.setGamepassword(StringUtils.isNotEmpty(goodsInfoAndAttrValueDto.getAccountPassword())?goodsInfoAndAttrValueDto.getAccountPassword():"123456");
        yxlmsyInfo.setGamepasswordqr(StringUtils.isNotEmpty(goodsInfoAndAttrValueDto.getAccountPassword())?goodsInfoAndAttrValueDto.getAccountPassword():"123456");
        yxlmsyInfo.setLevel("30");
        goodsBean.setPropertyList(yxlmsyInfo);
        return goodsBean;
    }
    YX7881GoodsBean hyrzInfo(GoodsInfoAndAttrValueDto goodsInfoAndAttrValueDto, YX7881GoodsBean goodsBean) {
        goodsBean.setGameId("A5468");
        switch (goodsInfoAndAttrValueDto.getSystemName() + goodsInfoAndAttrValueDto.getCarrierName()) {
            case "安卓QQ":
                goodsBean.setCarrierId("A5468Y004");
                goodsBean.setCarriername("QQ");
                goodsBean.setGroupId("A5468P001");
                goodsBean.setServerId("A5468P001001");
                break;
            case "安卓微信":
                goodsBean.setCarrierId("A5468Y003");
                goodsBean.setCarriername("微信");
                goodsBean.setGroupId("A5468P003");
                goodsBean.setServerId("A5468P003001");
                break;
            case "苹果QQ":
                goodsBean.setCarrierId("A5468Y006");
                goodsBean.setCarriername("QQ");
                goodsBean.setGroupId("A5468P002");
                goodsBean.setServerId("A5468P002001");
                break;
            case "苹果微信":
                goodsBean.setCarrierId("A5468Y005");
                goodsBean.setCarriername("微信");
                goodsBean.setGroupId("A5468P004");
                goodsBean.setServerId("A5468P004001");
                break;
        }
        HyrzInfo hyrzInfo = new HyrzInfo();
        hyrzInfo.setGameaccount(StringUtils.isNotEmpty(goodsInfoAndAttrValueDto.getAccountNumber())?goodsInfoAndAttrValueDto.getAccountNumber():goodsInfoAndAttrValueDto.getId()+"");
        hyrzInfo.setGamepassword("123456");
        hyrzInfo.setGamepasswordqr("123456");
        goodsBean.setPropertyList(hyrzInfo);
        return goodsBean;
    }

    //只保留中文
    private String onlyHanZi(String str) {
        String reg = "[^\u4e00-\u9fa5]";
        str = str.replaceAll(reg, "");
        return str;
    }



    /**
     * 封装 DNF 信息
     *
     * @param dto
     * @param goodsBean
     * @return
     */
    YX7881GoodsBean dnfInfo(GoodsInfoAndAttrValueDto dto, YX7881GoodsBean goodsBean) {
        goodsBean.setGameId("G10");
        String result = null;
        try {
            result = LieBaoCore.get_game_info("G10", null);
        } catch (Exception e) {
            e.printStackTrace();
        }
        if (StringUtils.isNotEmpty(result)) {
            JSONObject parse = JSONObject.parseObject(result, JSONObject.class);
            JSONObject params = parse.getJSONObject("data");
            List<JSONObject> servers = JSONObject.parseArray(params.getString("servers"), JSONObject.class);
            Map<String, JSONObject> serversCollect = servers.stream().collect(Collectors.toMap(s -> s.getString("name"), s -> s));
            GameAttribute attribute = gameAttributeMapper.selectGameAttributeById(dto.getServerId());
            if (!Objects.isNull(serversCollect.get(attribute.getFieldName()))) {//区服
                JSONObject jsonObject = serversCollect.get(attribute.getFieldName());
                goodsBean.setGroupId(jsonObject.getString("group_id"));
                goodsBean.setServerId(jsonObject.getString("id"));
                JSONObject json = new JSONObject();
                String profession = "鬼剑士（男）,鬼剑士（女）,格斗家（男）,格斗家（女）,神枪手（男）,神枪手（女）,魔法师（男）,魔法师（女）,圣职者（男）,圣职者（女）,暗夜使者,守护者,魔枪士,枪剑士,外传,弓箭手";
                json.put("profession", getPropertyParam(profession, dto.getF2()));
                json.put("record", "无5天封号记录");
                json.put("antiaddiction", "是");
                if (dto.getDes().contains("不可二次")) {
                    json.put("canSecond", "不可二次");
                } else {
                    json.put("canSecond", "可二次");
                }
                json.put("code1", dto.getDes());
                json.put("code3", null);
                json.put("code5", "无");
                json.put("code4", 1);
                json.put("code6", "无");
                json.put("code7", "无天空装扮");
                json.put("gameaccount", dto.getAccountNumber());
                json.put("gamepassword", dto.getAccountPassword());
                json.put("gamepassword2", dto.getAccountPassword());
                json.put("gamerole", "wenkefu");
                json.put("secondpassword", dto.getAccountPassword());
                json.put("pwdstore", "wenkefu");
                goodsBean.setPropertyList(json);
            }
            return goodsBean;
        }


        return goodsBean;
    }

    private String getPropertyParam(String content, String param) {
        if (StringUtils.isNotEmpty(param)) {
            List<GameAttribute> gameAttributes = gameAttributeMapper.selectGameAttributeListByIds((Long[]) ConvertUtils.convert(param.split(","), Long.class));
            if (CollectionUtils.isNotEmpty(gameAttributes)) {
                List<String> split = Arrays.asList(content.split(","));
                List<String> collect = gameAttributes.stream().map(s -> s.getFieldName()).collect(Collectors.toList());
                if (CollectionUtils.isNotEmpty(collect)) {
                    StringBuilder builder = new StringBuilder();
                    for (String s : collect) {
                        if (split.contains(s)) {
                            builder.append(s + ",");
                        }
                    }
                    if (builder.length() > 0) {
                        String substring = builder.substring(0, builder.length() - 1);
                        return substring;
                    }
                }
            }
        }
        return "无";
    }

    public static void main(String[] args) {
        SalePartner s = new SalePartner();
        s.setSaleKey("yuduShop");
        s.setOther("17d8230904ae40fad66caf2113ab294d");
        s.setTwoOther("http://open.api.7881.com/web-api");
        s.setThreeOther("124408372,115235020");
        getGameInfo("A5661",s);

    }

    /**
     * String字符串的值 =号拼接 转Map
     *
     * @param b
     * @return
     */
    Map stringTOmap(String b) {
        if (StringUtils.isNotEmpty(b)) {
            b = b.replaceAll(" ", "");
        }
        Map docType = new HashMap();
        StringTokenizer items;
        for (StringTokenizer entrys = new StringTokenizer(b, ","); entrys.hasMoreTokens();
             docType.put(items.nextToken(), items.hasMoreTokens() ? ((Object) (items.nextToken())) : null)) {
            items = new StringTokenizer(entrys.nextToken(), "=");
        }
        return docType;
    }


    // 以下为新写的方法
    private String reRedioValue(String value) {
        String reStr = "";
        if (StringUtils.isNotEmpty(value)) {
            GameAttribute gameAttribute =
                    gameAttributeService.selectGameAttributeById(Long.valueOf(value));
            if (gameAttribute != null) {
                if (StringUtils.isNotEmpty(gameAttribute.getFieldName())) {
                    reStr = gameAttribute.getFieldName();
                }

            }
        }
        return reStr;
    }

    String baohan(String str1, String str2) {
        String res = "";
        if (StringUtils.isEmpty(str2)) {
            return res;
        }
        String[] str1sz = str1.split(",");
        for (String s : str1sz) {
            if (s.contains(str2)) {
                res = s;
                break;
            }
        }
        return res;
    }

    private List<GameAttribute> getGameAttributs(String ids) {
        if (StringUtils.isEmpty(ids)) {
            return new ArrayList<>();
        }
        return gameAttributeMapper.selectGameAttributeListByIds((Long[]) ConvertUtils.convert(ids.split(","),
                Long.class));
    }

    private String reIds(String allIds, String ids) {
        if (StringUtils.isNotEmpty(ids)) {
            if (StringUtils.isNotEmpty(allIds)) {
                allIds = allIds + "," + ids;
            } else {
                allIds = ids;
            }
        }
        return allIds;
    }

    String baohanGetAll(String str1, String str2) {
        String res = "";
        if (StringUtils.isEmpty(str2)) {
            return res;
        }
        String[] str1sz = str1.split(",");
        for (String s : str1sz) {
            if (str2.contains(s)) {
                res = res + "," + s;
            }
        }
        if (res.length() > 0) {
            res = res.replaceFirst(",", "");
        }
        return res;
    }


}